package com.neusoft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Points;
import com.neusoft.service.PointsService;

@RefreshScope
@RestController
@RequestMapping("/PointsController")
public class PointsController {
    @Autowired
    private PointsService pointsService;

    @GetMapping("/listPointsByOrderUserId/{userId}")
    public CommonResult<List> listPointsByOrderUserId(
    		@PathVariable("userId") String userId
    		) throws Exception {
    	List<Points> list = pointsService.listPointsByOrderUserId(userId);
    	return new CommonResult(200, "success（10700）", list);
    }

    @PostMapping("/savePoints/{pointId}/{userId}/{point}/{date}/{valid}")
    public CommonResult<Integer> savePoints(
    		@PathVariable("pointId") Integer pointId,
    		@PathVariable("userId") String userId,
    		@PathVariable("point") Integer point,
    		@PathVariable("date") String date,
    		@PathVariable("valid") Integer valid
    		) throws Exception {
    	Points param = new Points();
    	param.setUserId(userId);
    	param.setPointId(pointId);
    	param.setPoint(point);
    	param.setDate(date);
    	param.setValid(valid);
    	int result = pointsService.savePoints(param);
        return new CommonResult(200, "success", result);
    }

    @PutMapping("/updatePoints/{pointId}/{point}")
    public CommonResult<Integer> updatePoints(
    		@PathVariable("pointId") Integer pointId,
    		@PathVariable("point") Integer point
    		) throws Exception {
    	int result = pointsService.updatePoints(pointId, point);
    	return new CommonResult(200, "success", result);
    }

    @DeleteMapping("/removePoints/{pointId}")
    public CommonResult<Integer> removePoints(
    		@PathVariable("pointId") Integer pointId
    		) throws Exception {
    	int result = pointsService.removePoints(pointId);
    	return new CommonResult(200, "success", result);
    }

}
